package com.fr.report.core.barcode.output;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;

public class GraphicsOutput extends AbstractOutput
{
  public static final int BARS_TEXT_VGAP = 4;
  private final Graphics2D g;

  public GraphicsOutput(Graphics2D paramGraphics2D, Font paramFont, double paramDouble1, double paramDouble2, boolean paramBoolean, Color paramColor1, Color paramColor2)
  {
    super(paramFont, paramDouble1, paramDouble2, paramBoolean, 1.0D, paramColor1, paramColor2);
    this.g = paramGraphics2D;
  }

  public void beginDraw(double paramDouble1, double paramDouble2)
  {
  }

  public void endDraw()
  {
  }

  public void drawBar(int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean)
  {
    if (this.painting)
    {
      if (paramBoolean)
        this.g.setColor(this.foregroundColour);
      else
        this.g.setColor(this.backgroundColour);
      this.g.fillRect((int)(this.scalar * paramInt1), (int)(this.scalar * paramInt2), (int)(this.scalar * paramInt3), (int)(this.scalar * paramInt4));
    }
  }

  public double drawText(String paramString, double paramDouble1, double paramDouble2, double paramDouble3)
  {
    double d2;
    int j;
    if (this.font == null)
      return 0.0D;
    TextLayout localTextLayout = new TextLayout(paramString, this.font, this.g.getFontRenderContext());
    float f = (float)((paramDouble3 - paramDouble1 - localTextLayout.getBounds().getWidth()) / 2.0D + paramDouble1);
    double d1 = (float)(paramDouble2 + localTextLayout.getBounds().getHeight() + 4.0D);
    int i = (int)(d1 - paramDouble2 + 1.0D);
    if (this.painting)
    {
      this.g.setColor(this.backgroundColour);
      this.g.fillRect((int)paramDouble1, (int)paramDouble2, (int)(paramDouble3 - paramDouble1), i);
      this.g.setColor(this.foregroundColour);
      d2 = (paramDouble3 - paramDouble1) / paramString.length();
      for (j = 0; j < paramString.length(); ++j)
        this.g.drawString("" + paramString.charAt(j), (int)(paramDouble1 + d2 * j + d2 / 2.0D), (int)d1);
    }
    return i;
  }
}